// pages/dot/dot.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showView: true,
    url: getApp().globalData.url, //链接路径
    list:{},    //网点列表
    detail:{},  //房源详情
    showView:true, //显示状态
    showView_ID: 0,
    cityname:'',//搜索默认值
    selecthistory:'',//搜索历史
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    showView: (options.showView == "true" ? true : false)
    wx.request({
      url: this.data.url + "Smallprogram/index/dot_select",
      success: function (res) {
        that.setData({
          list: res.data
        });
        ;
      },
      fail: function (res) {
        wx.showToast({
          title: '页面加载失败！！！',
        })
      },
    })
  },
  /**
    * 网点详情
    */
  dotdetail: function (event) {
    var that = this;
    // console.log(event);
    if (event.currentTarget.dataset.id > 0) {
      wx.request({
        url: this.data.url + "Smallprogram/index/dot_group_details",
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          id: event.currentTarget.dataset.id,
        },
        success: function (res) {
          that.setData({
            detail: res.data,
            showView: false,
            showView_ID: event.currentTarget.dataset.id,
          });
        }
      });
    } else {
      that.setData({
        showView: true,
        showView_ID: 0,
      });
    }
  },
  /**
    * 点击搜索
    */
  citynameInput:function(e){
   this.setData({
      cityname: e.detail.value
    })
  },
  dotseaimg_click: function (event){
    var that = this;
    wx.showToast({
      title: '请稍后...',
      icon: 'loading',
      duration: 500
    });
    wx.request({
      url: this.data.url + "Smallprogram/index/dot_select",
      method:"POST",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        areaskeyword: this.data.cityname,
      },
      success: function (res) {
        if(res.data.state == "success"){
          var addhistory = that.data.selecthistory ? that.data.selecthistory:(new Array());
            
          if (!that.data.cityname){
            that.setData({
              showView: true,
              showView_ID: 0,
            });
          }else{
            for (var i = 0; i < res.data.list.length;i++){
              var panduan = true;
              for (var j = 0; j < addhistory.length; j++) {
                if (addhistory[j]['title'] == res.data.list[i]['title'] ){
                  panduan = false;
                  break;
                }
              }
             
              if (panduan){
                var addhistory_length = addhistory.length > 0 ? addhistory.length:0;
                addhistory[addhistory_length] = res.data.list[i];
              }
            }
          } 
          that.setData({
            selecthistory: addhistory,
            list: res.data.list
          });
        }else{
          wx.showToast({
            title: '暂无该网点',
            icon: 'none',
            duration: 500
          });
        }
      },
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  showall:function(){
    //console.log(this.data.showView);
    var that = this;
    that.setData({
      showView: (!that.data.showView)
    })
  }
})